package com.zzjson.client;

import com.zzjson.RpcRequest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2020 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.client</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2020年02月23日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class RemoteInvocationHandler implements InvocationHandler {
	private String host;
	private int port;

	public RemoteInvocationHandler(String host, int port) {
		this.host = host;
		this.port = port;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("invocation Handler");

		RpcRequest rpcRequest = new RpcRequest();
		rpcRequest.setClassName(method.getDeclaringClass().getName());
		rpcRequest.setMethodName(method.getName());
		rpcRequest.setParameters(args);
		rpcRequest.setVersion("v2.0");
		RpcNetTransport rpcNetTransport = new RpcNetTransport(host, port);
		Object send = rpcNetTransport.send(rpcRequest);
		return send;
	}
}
